package com.dts.evaluate.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by user on 2016/9/19.
 */
public class DashView extends View {
    private Paint paint;
    private Path path = new Path();

    public DashView(Context context) {
        super(context);
        init(context);
    }

    public DashView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DashView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.GRAY);
        PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);
        paint.setPathEffect(effects);

    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();

        path.moveTo(0,height/2);
        path.lineTo(width,height/2);
        canvas.drawPath(path, paint);

    }
}
